package com.jiyi.view;

import android.content.Context;
import android.widget.TextView;

import com.github.mikephil.charting.components.MarkerView;
import com.github.mikephil.charting.data.CandleEntry;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.utils.MPPointF;
import com.github.mikephil.charting.utils.Utils;
import com.swift.maintenance.R;

/**
 * Custom implementation of the MarkerView.
 * 
 * @author Philipp Jahoda
 */
public class MyMarkerView extends MarkerView {

	private TextView tvContent;

	private MPPointF mOffset2 = new MPPointF();

	public MyMarkerView(Context context, int layoutResource) {
		super(context, layoutResource);

		tvContent = (TextView) findViewById(R.id.tvContent);
	}

	// callbacks everytime the MarkerView is redrawn, can be used to update the
	// content (user-interface)
	@Override
	public void refreshContent(Entry e, Highlight highlight) {

		if (e instanceof CandleEntry) {

			CandleEntry ce = (CandleEntry) e;

			tvContent.setText("" + Utils.formatNumber(ce.getHigh(), 0, true));
		} else {
			tvContent.setText((int)e.getX()+"月	"+(int)e.getY()+"次");
		}

		super.refreshContent(e, highlight);
	}

	@Override
	public MPPointF getOffset() {
		return new MPPointF(-(getWidth() / 2), -getHeight());
	}

//	@Override
//	public MPPointF getOffsetForDrawingAtPoint(float posX, float posY) {
//		MPPointF offset = getOffset();
//		mOffset2.x = offset.x;
//		mOffset2.y = offset.y;
//
//		// Chart chart = getChartView();
//		//
//		// float width = getWidth();
//		// float height = getHeight();
//
//		// if (posX + mOffset2.x < 0) {
//		// mOffset2.x = - posX;
//		// } else if (chart != null && posX + width + mOffset2.x >
//		// chart.getWidth()) {
//		// mOffset2.x = chart.getWidth() - posX - width;
//		// }
//		//
//		// if (posY + mOffset2.y < 0) {
//		// mOffset2.y = - posY;
//		// } else if (chart != null && posY + height + mOffset2.y >
//		// chart.getHeight()) {
//		// mOffset2.y = chart.getHeight() - posY - height;
//		// }
//
//		return mOffset2;
//	}
}
